package cc.lj.internal.coupons.interfaces.facade;

import cc.lj.internal.api.merchant.dto.PropertyRelatonApiDTO;
import cc.lj.internal.core.exception.SysExceptionEnum;
import cc.lj.internal.core.http.HttpResult;
import cc.lj.internal.core.model.PageBean;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.application.service.CapMerchantAppService;
import cc.lj.internal.coupons.interfaces.dto.CapMerchantDTO;
import cc.lj.internal.coupons.interfaces.dto.command.AddCapMerchantCommand;
import cc.lj.internal.coupons.interfaces.dto.query.CapMerchantListQuery;
import cc.lj.internal.coupons.interfaces.dto.query.SelectMerchantCommand;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import javax.validation.constraints.Min;
import java.util.List;

/**
 * 封顶额商户表接口
 * @author liangxifeng
 * @date 2021-12-20
 */
@RestController
@Slf4j
@Validated
@Api(tags = "封顶额商户表相关接口")
@RequestMapping("capMerchant")
public class CapMerchantController {
    @Resource(name = "capMerchantAppService")
    private CapMerchantAppService capMerchantAppService;

    /**
     * 新增封顶额活动批次
     * @param addCmdList 新增封顶额商户表command list
     * @return 新增后的主键 list
     */
    @PostMapping("/add")
    @ApiOperation(value = "封顶额商户表批量新增表接口",notes = "错误码：1005001029")
    public HttpResult<List<Integer>> save(@Valid @RequestBody List<AddCapMerchantCommand> addCmdList)
    {
        List<Integer> saveRes = capMerchantAppService.save(addCmdList);
        log.info("新增封顶额商户controller结果="+saveRes);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),saveRes);
    }
    /**
     * 封顶额活动批次表查询列表接口
     * @param pageParam<CapBatchQuery> 封顶额活动批次表查询query
     * @return 封顶额活动批次list
     */
    @PostMapping("/getPage")
    @ApiOperation(value = "封顶额商户查询列表接口",notes = "错误码：无")
    public HttpResult<PageBean<CapMerchantDTO>> getPage(@Valid @RequestBody PageParam<CapMerchantListQuery> pageParam) {
        PageBean<CapMerchantDTO> pageBean = capMerchantAppService.selectPage(pageParam);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),pageBean);
    }
    /**
     * 通过主键删除
     * @param id
     * @return 影响行数
     */
    @PostMapping("/deleteById")
    @ApiOperation(value = "通过主键删除封顶额商户表接口",notes = "错误码：1005001039,1005001006,1005001035,1005001037,1005001031")
    public HttpResult<Integer> deleteById(@Min(1) @RequestParam Integer id ) {
        Integer rows = capMerchantAppService.deleteById(id);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),rows);
    }


    /**
     * 针对某个单独商户生成封顶额
     * @param id 商户表主键
     * @return 该商户的封顶额
     */
    @PostMapping("/createCap")
    @ApiOperation(value = "针对单个商户生成封顶额接口",notes = "错误码：1005001039,1005001041,1005001006,1005001045,1005001049,1005001043")
    public HttpResult<Integer> createCapValue(@Min(1) @RequestParam Integer id) {
        Integer capValue = capMerchantAppService.createCapValue(id);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),capValue);
    }

    /**
     * 商户批量生成封顶额
     * @param modelId 倍数模型表主键
     * @return 该倍数模型下所有商户总封顶额
     */
    @PostMapping("/batchCreateCap")
    @ApiOperation(value = "商户批量生成封顶额接口",notes = "错误码：1005001049,1005001006,1005001045,1005001033,1005001047,1005001043")
    public HttpResult<Integer> batchCreateCapValue(@Min(1) @RequestParam Integer modelId) {
        Integer capTotalValue = capMerchantAppService.batchCreateCapValue(modelId);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),capTotalValue);
    }

    /**
     * 选择商户list接口
     * @param selectMerchantCmd
     * @return 在租且未被指定倍数模型绑定的商户list
     */
    @GetMapping("/srcMerchantList")
    @ApiOperation(value = "选择商户List接口",notes = "错误码：无")
    public HttpResult<List<CapMerchantDTO>> selelctMerchant(SelectMerchantCommand selectMerchantCmd){
        List<CapMerchantDTO> merchantList = capMerchantAppService.selectMerchant(selectMerchantCmd);
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),merchantList);
    }

    /**
     * 查询展位区域list
     * @return 返回展位区域list
     */
    @GetMapping("/showAreaList")
    @ApiOperation(value = "展位区域List接口",notes = "错误码：无")
    public HttpResult<List<PropertyRelatonApiDTO>> getShowAreaList(){
        List<PropertyRelatonApiDTO> relatonApiDTOList = capMerchantAppService.getShowArea();
        return HttpResult.success(SysExceptionEnum.SUCCESS.getCode(),SysExceptionEnum.SUCCESS.getMessage(),relatonApiDTOList);
    }
}
